package frame.form;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

public class ConstructForm {

	public ConstructForm() {

	}

	public static ActionForm construct(String classPath, HttpServletRequest req) {
		ActionForm form = null;
		try {
			Class clazz = Class.forName(classPath);
			form = (ActionForm) clazz.newInstance();
			Field[] f_attrs = form.getClass().getDeclaredFields();
			
			for(Field f_attr : f_attrs){
				f_attr.setAccessible(true);
				f_attr.set(form, req.getParameter(f_attr.getName()));
				f_attr.setAccessible(false);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return form;
	}
}
